Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ldapjs

Package Overview
Dependencies
Maintainers
6
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ldapjs

LDAP client and server APIs

  • 2.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
180K
decreased by-8.2%
Maintainers
6
Weekly downloads
 
Created

What is ldapjs?

ldapjs is a pure JavaScript, from-scratch framework for implementing LDAP clients and servers in Node.js. It is designed to be simple, extensible, and robust, making it suitable for a wide range of LDAP-related tasks.

What are ldapjs's main functionalities?

Creating an LDAP Client

This feature allows you to create an LDAP client and bind to an LDAP server. The code sample demonstrates how to connect to an LDAP server running on localhost and bind using a distinguished name (DN) and password.

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'ldap://127.0.0.1:389'
});

client.bind('cn=root', 'secret', (err) => {
  if (err) {
    console.error('Error binding to LDAP server:', err);
  } else {
    console.log('Successfully bound to LDAP server');
  }
});

Searching the LDAP Directory

This feature allows you to search the LDAP directory. The code sample demonstrates how to perform a search for entries with the surname 'Smith' and retrieve their distinguished names, surnames, and common names.

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'ldap://127.0.0.1:389'
});

client.bind('cn=root', 'secret', (err) => {
  if (err) {
    console.error('Error binding to LDAP server:', err);
    return;
  }

  const opts = {
    filter: '(sn=Smith)',
    scope: 'sub',
    attributes: ['dn', 'sn', 'cn']
  };

  client.search('o=example', opts, (err, res) => {
    if (err) {
      console.error('Error searching LDAP directory:', err);
      return;
    }

    res.on('searchEntry', (entry) => {
      console.log('Entry:', entry.object);
    });
    res.on('searchReference', (referral) => {
      console.log('Referral:', referral.uris.join());
    });
    res.on('error', (err) => {
      console.error('Search error:', err);
    });
    res.on('end', (result) => {
      console.log('Search result:', result);
    });
  });
});

Adding an Entry to the LDAP Directory

This feature allows you to add an entry to the LDAP directory. The code sample demonstrates how to add a new entry with common name 'John Doe', surname 'Doe', and email 'john.doe@example.com' to the directory.

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'ldap://127.0.0.1:389'
});

client.bind('cn=root', 'secret', (err) => {
  if (err) {
    console.error('Error binding to LDAP server:', err);
    return;
  }

  const entry = {
    cn: 'John Doe',
    sn: 'Doe',
    email: 'john.doe@example.com',
    objectclass: 'inetOrgPerson'
  };

  client.add('cn=John Doe, o=example', entry, (err) => {
    if (err) {
      console.error('Error adding entry to LDAP directory:', err);
    } else {
      console.log('Entry added successfully');
    }
  });
});

Modifying an Entry in the LDAP Directory

This feature allows you to modify an entry in the LDAP directory. The code sample demonstrates how to replace the email attribute of an existing entry with a new email address.

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'ldap://127.0.0.1:389'
});

client.bind('cn=root', 'secret', (err) => {
  if (err) {
    console.error('Error binding to LDAP server:', err);
    return;
  }

  const change = new ldap.Change({
    operation: 'replace',
    modification: {
      email: 'john.new@example.com'
    }
  });

  client.modify('cn=John Doe, o=example', change, (err) => {
    if (err) {
      console.error('Error modifying entry in LDAP directory:', err);
    } else {
      console.log('Entry modified successfully');
    }
  });
});

Deleting an Entry from the LDAP Directory

This feature allows you to delete an entry from the LDAP directory. The code sample demonstrates how to delete an entry with the distinguished name 'cn=John Doe, o=example' from the directory.

const ldap = require('ldapjs');
const client = ldap.createClient({
  url: 'ldap://127.0.0.1:389'
});

client.bind('cn=root', 'secret', (err) => {
  if (err) {
    console.error('Error binding to LDAP server:', err);
    return;
  }

  client.del('cn=John Doe, o=example', (err) => {
    if (err) {
      console.error('Error deleting entry from LDAP directory:', err);
    } else {
      console.log('Entry deleted successfully');
    }
  });
});

Other packages similar to ldapjs

FAQs

Package last updated on 08 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc